#include "macro.h"
#include <QHash>
#include <QRegExp>

QHash<quint8,QByteArray> *hashCmdAckStatusIDMeaning=new QHash<quint8,QByteArray>; //变量定义
QRegExp *regExpValidIP=new QRegExp("[1-9][0-9]{0,2}\\.[0-9]{0,3}\\.[0-9]{0,3}\\.[0-9]{0,3}"); //变量定义

 unsigned short MyCRC16(char* data, unsigned short len)
{
    unsigned short crcsum=0;
    unsigned short *p=(unsigned short*)data;
    while (len> 1)
    {
        crcsum^=*p++;
        len -=2;
    }
    if (len)
    {
        crcsum^= *( unsigned char *)p;
    }
    return crcsum;
}
 QByteArray getCRC16Hex(QByteArray dataToBeChecked)
 {
     quint16 crcsum=MyCRC16(dataToBeChecked.data(),dataToBeChecked.length());
     return mySetNumHex(crcsum,4);
 }

 QByteArray mySetNumHex(qint64 uint64Num, quint8 width)
 {
     QByteArray result;
     result=result.setNum(uint64Num,16).rightJustified(width,'0',true);
     return result;
 }
